#ifndef MODULE_H
#define MODULE_H

typedef struct {
    COVALUE_HEAD
    CoValue *m_name;        /* CoString: name */
    CoValue *m_func_map;    /* CoDict: name -> function */
    CoValue *m_functions;   /* CoList: functions */
    CoValue *m_strings;     /* CoList: string constants */
    CoValue **m_globals;    /* array: global variables */
    int m_num_global;       /* number of global variables */
    int m_code_size;        /* size of binary instrucions */
    char *m_code;           /* binary instrucions */
} CoModule;

extern CoType CoModule_Type;

#define COMODULE_CHECK(self)   CO_CHECK_TYPE(self, &CoModule_Type)

CoValue *CoModule_New(CoValue *mod_name, CoValue *functions, CoValue *strings, int num_global, char *code_start, int code_size);
CoValue *CoModule_GetFunctionByName(CoValue *self, CoValue *func_name);
CoValue *CoModule_GetFunctionByIndex(CoValue *self, int index);
CoValue *CoModule_GetStringByIndex(CoValue *self, int index);
CoValue **CoModule_GetGlobalPtrByIndex(CoValue *self, int index);

#define CoModule_GET_CODE(self)     (((CoModule *)self)->m_code)

void CoModule_DumpCode(CoValue *self);

#endif
